<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言</title>
</head>
<body>
<h1>留言</h1>

<!-- Form to add a new message -->
<form action="addMessage" method="post">
    <label for="title">标题</label>
    <input type="text" id="title" name="title" required>
    <br><br>

    <label for="content">内容</label>
    <textarea id="content" name="content" rows="5" required></textarea>
    <br><br>
    <c:choose>
        <c:when test="${empty sessionScope.username}">
            <a href=".">登录</a>后才能留言
        </c:when>
        <c:otherwise>
            <button type="submit">发送</button>
        </c:otherwise>
    </c:choose>

</form>

<!-- Display error message if submission failed -->
<c:choose>
    <c:when test="${param.error != null}">
        <p style="color: red;">${param.error}</p>
    </c:when>
</c:choose>

<a href="messages">不发了</a>

</body>
</html>
